package com.xunqi.activemq.produce;

import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @Description:
 * @Created: with IntelliJ IDEA.
 * @author: 夏沫止水
 * @createTime: 2020-06-23 09:29
 **/

@Component
public class QueueProduce {

    //JmsMessagingTemplate是Springboot的Jms模板,Spring的是JmsTemplate
    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    //把ConfigBean类的ActiveMQQueue注入进来
    @Autowired
    private ActiveMQQueue queue;

    public void produceMsg() {

        jmsMessagingTemplate.convertAndSend(queue,"********：" + UUID.randomUUID().toString().substring(0,6));
    }


    /**
     * 间隔时间三秒钟定投
     */
    @Scheduled(fixedDelay = 3000)
    public void producerMsgScheduled() {
        jmsMessagingTemplate.convertAndSend(queue,"********Scheduled：" + UUID.randomUUID().toString().substring(0,6));
        System.out.println("********Scheduled已投递");
    }

}
